module.exports = {
  webpack: {
    configure(webpackConfig) {
      if (webpackConfig.mode === 'production') {
        // * 抽离公共代码,只在生产环境
        if (webpackConfig.optimization == null) {
          webpackConfig.optimization = {}
        }
        webpackConfig.optimization.splitChunks = {
          chunks: 'all',
          cacheGroups: {
            // TODO 单独抽离antd、reactDom,会独立于node_modules其他插件,并赋予一定权重priority
            // src是我们自己的包,第三方的包就会分成三个包,一共四个包
            antd: {
              name: 'antd-chunk',
              test: /antd/,
              priority: 100,
            },
            reactDom: {
              name: 'reactDom-chunk',
              test: /react-dom/,
              priority: 99,
            },
            // 第三方插件
            vendors: {
              name: 'vendors-chunk',
              test: /node_modules/,
              priority: 98,
            },
          },
        }
      }
      return webpackConfig
    },
  },

  devServer: {
    port: 8000, //B端,前端
    proxy: {
      '/api': 'http://localhost:3001',
    },
  },
}
